<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <meta name="keywords" content=""/>
    <meta name="description" content=""/>
    <title>管理平台</title>
    <link rel="stylesheet" href="${base}/static/layui/css/layui.css"/>
    <link rel="stylesheet" href="${base}/static/css/admin.css"/>
</head>
<body>
	<div class="container">
		<div class="content-search">
			<form class="layui-form layui-form-pane" action="${base}/goods/goodsList">
				<div class="layui-inline">
					<label class="layui-form-label" >产品</label>
					<div class="layui-input-block">
						<input name="keyWord" value="${keyWord!}"  autocomplete="off" placeholder="产品名称" class="layui-input" type="text"/>
						<input name="inStock" type="hidden" value="${inStock}"/>
					</div>
				</div>

				<div class="layui-inline"><button class="layui-btn" lay-submit="" type="submit">查询</button></div>
			</form>
		</div>
		<div class="tar mt10">
			<button class="layui-btn layui-btn-normal layui-btn-small add">+添加产品</button>
		</div>
		<div class="table-listm roll-x">
			<table class="layui-table" lay-skin="line">
			  <thead>
			    <tr>
			      <th>产品名</th>
					<th>价格</th>
					<th>库存</th>
			      <th>创建时间</th>
					<th>状态</th>
			      <th>操作</th>
			    </tr> 
			  </thead>
			  <tbody>
			  <% for(goods in list){%>
			    <tr ondblclick="buyGoods('${goods.id}','${goods.name}','${goods.num}')">
			        <td>${goods.name}</td>
			        <td>${goods.price}</td>
					<td>${goods.num}</td>
			      <td>${goods.createdate,dateFormat="yyyy-MM-dd HH:mm:ss"}</td>
					<td>${goods.state==1?"正常":"下架"}</td>
			      <td>
			      	<button class="layui-btn layui-btn-warm layui-btn-small edit" id="${goods.id}">编辑</button>
					<button class="layui-btn layui-btn-danger layui-btn-small a4" id="${goods.id}">下架</button>
			      </td>
			    </tr>
			  <%}%>
			  </tbody>
			</table>   
		</div>
	</div>
	<div id="table-pages" style="text-align:center"></div>
	<script type="text/javascript" src="${base}/static/layui/jquery.min.js"></script>
	<script type="text/javascript" src="${base}/static/layui/layui.js"></script>
	<script type="text/javascript" src="${base}/static/js/jquery.form.js"></script>
	<script type="text/javascript" src="${base}/static/js/util.js"></script>

    <script>
        //双击操作，给父页面传值
        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
        function buyGoods(id,name,num) {
            parent.document.getElementById("content").innerHTML+=" <tr>  <td>\n" +
                " <input type=\"hidden\" name=\"goodsId\" value='"+id+"' />\n" +
                " <input type=\"text\"  placeholder=\"产品名称\" value='"+name+"'  autocomplete=\"off\" class=\"layui-input\">\n" +
                "	</td>\n" +
                "	<td>\n" +
                "		<input type=\"number\" name=\"num\" value='1'  placeholder=\"件数\" max='"+num+"' min='0' autocomplete=\"off\" class=\"layui-input\">\n" +
                "		</td>\n" +
                "<td>\n" +
            "				  <div class=\"layui-btn layui-btn-danger del\" style=\" min-width: 150px;\">删除</div>\n" +
            "			  </td></tr>";
            parent.layer.close(index);
        }

		function shutDownOrUp(userId) {
            $.ajax({
                type : "POST", //提交方式
                url : "${base}/goods/shutDownOrUp",//路径
                data : {
                    "goodsId" : userId
                },//数据，这里使用的是Json格式进行传输
                success : function(data) {//返回数据根据结果进行相应的处理
                    if(data.code==200){
                        layer.msg('操作成功！',{time: 2000});

                    }else{
                        layer.msg(data.message,{time: 2000});
                    }
                }
            });
        }
        

        
		layui.use(['jquery', 'laydate','form','layer','laypage'], function(){

			var $ = layui.jquery,
			    laydate = layui.laydate,
			    layer = layui.layer,
			    laypage = layui.laypage;

			// 分页
			 laypage({
			    cont: 'table-pages'
			    ,pages:${page.pages}
			    ,skip: true
				 ,curr:${page.pageNum}
				,jump:function(e,first){
                     if(!first){
                         var myform=$('.layui-form'); //得到form对象
                         var tmpInput=$("<input type='text' name='pageNum'/>");
                         tmpInput.attr("value", e.curr);
                         myform.append(tmpInput);
                         myform.submit();
                     }
                 }
             });

		    // 下架操作
		    $(document).on("click", ".a4", function() {
		        var userId=this.id;
			    layer.open({
			      title:"下架操作"
				  ,content: '您确认要下架该商品吗？'
				  ,btn: ['取消', '确认']
				  ,yes: function(index, layero){
				       layer.closeAll();
				  }
				  ,btn2: function(index, layero){
                        shutDownOrUp(userId);
                        thisWindowReload(1000);

				  }
				});
			});
			// 解冻操作
			$(document).on("click", ".a1", function() {
                var userId=this.id;
			    layer.open({
			      title:"解冻操作"
				  ,content: '您确认要解冻该管理员吗？'
				  ,btn: ['取消', '确认']
				  ,yes: function(index, layero){
				       layer.closeAll();
				  }
				  ,btn2: function(index, layero){
                        freezeOrUnfreeze(userId);
                        thisWindowReload(1000);
				  }
				});
			});

			// 发布商品
			$(document).on("click", ".add", function() {
			    layer.open({
			      type:2
			      ,area:['80%', '90%']
			      ,title:"添加产品"
				  ,content: '${base}/goods/addGoods'
				});
			});

            // 修改客户
            $(document).on("click", ".edit", function() {
                var id=this.id;
                layer.open({
                    type:2
                    ,area:['80%', '90%']
                    ,title:"编辑产品"
                    ,content: '${base}/goods/addGoods?goodsId='+id
                });
            });



		});
	</script>
</body>
</html>